options(repos = "https://cran.rstudio.com/")
install.packages("Rtools")
## Installing package into 'C:/Users/Harinath/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## Warning: package 'Rtools' is not available for this version of R
##
## A version of this package for your version of R might be available elsewhere,
## see the ideas at
## https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
install.packages("readxl")
## Installing package into 'C:/Users/Harinath/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## package 'readxl' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\Harinath\AppData\Local\Temp\RtmpYjUtEL\downloaded_packages
library("readxl")
## Warning: package 'readxl' was built under R version 4.3.2
pfizer <- read_excel("C:\\Users\\Harinath\\Documents\\GitHub\\Statistical_graphs_and_exploration_using_R\\pfizer.xlsx")
Moderna <- read_excel("C:\\Users\\Harinath\\Documents\\GitHub\\Statistical_graphs_and_exploration_using_R\\Moderna.xlsx")
janssen <- read_excel("C:\\Users\\Harinath\\Documents\\GitHub\\Statistical_graphs_and_exploration_using_R\\janssen.xlsx")
library(tidyverse)
## Warning: package 'readr' was built under R version 4.3.2
## Warning: package 'stringr' was built under R version 4.3.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(dplyr)
library(devtools)
## Loading required package: usethis
devtools::install_github('FIRST-Data-Lab/IDDA', force = TRUE)
## Downloading GitHub repo FIRST-Data-Lab/IDDA@HEAD
## Warning in untar2(tarfile, files, list, exdir, restore_times): skipping pax
## global extended headers
## Warning in untar2(tarfile, files, list, exdir, restore_times): skipping pax
## global extended headers
## ── R CMD build ─────────────────────────────────────────────────────────────────
##
checking for file 'C:\Users\Harinath\AppData\Local\Temp\RtmpYjUtEL\remotes2a0057a03dd2\FIRST-Data-Lab-IDDA-7439336/DESCRIPTION' ...
✔ checking for file 'C:\Users\Harinath\AppData\Local\Temp\RtmpYjUtEL\remotes2a0057a03dd2\FIRST-Data-Lab-IDDA-7439336/DESCRIPTION'
##
─ preparing 'IDDA':
## checking DESCRIPTION meta-information ...
✔ checking DESCRIPTION meta-information
##
─ checking for LF line-endings in source and make files and shell scripts
##
─ checking for empty or unneeded directories
##
NB: this package now depends on R (>=
NB: this package now depends on R (>= 3.5.0)
##
WARNING: Added dependency on R >= 3.5.0 because serialized objects in
## serialize/load version 3 cannot be read in older versions of R.
## File(s) containing such objects:
## 'IDDA/data/CA.county.ts.rda' 'IDDA/data/D.county.rda'
## 'IDDA/data/D.state.rda' 'IDDA/data/I.county.rda'
## 'IDDA/data/I.state.rda' 'IDDA/data/PosTest.state.rda'
## 'IDDA/data/Test.state.rda' 'IDDA/data/counties1.rda'
## 'IDDA/data/counties2.rda' 'IDDA/data/county.top10.long.rda'
## 'IDDA/data/county.top10.rda' 'IDDA/data/features.county.rda'
## 'IDDA/data/features.state.rda' 'IDDA/data/fore.rda'
## 'IDDA/data/policy.county.rda' 'IDDA/data/pop.county.rda'
## 'IDDA/data/pop.state.rda' 'IDDA/data/state.long.rda'
## 'IDDA/data/state.ts.rda' 'IDDA/data/states1.rda'
##
─ building 'IDDA_1.0.0.tar.gz'
##
##
## Installing package into 'C:/Users/Harinath/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
State <- pfizer$Jurisdiction
Date <- pfizer$Week.of.Allocations
Pfizer.1st.Dose.Allocations <- pfizer$X1st.Dose.Allocations
Pfizer.2nd.Dose.Allocations <- pfizer$X2nd.Dose.Allocations
Moderna.1st.Dose.Allocations <- Moderna$X1st.Dose.Allocations
Moderna.2nd.Dose.Allocations <- Moderna$X2nd.Dose.Allocations
Janssen.1st.Dose.Allocations <- janssen$X1st.Dose.Allocations
All.Dose.Allocations <- 0.5 *(Pfizer.2nd.Dose.Allocations+Pfizer.1st.Dose.Allocations+Moderna.1st.Dose.Allocations + Moderna.2nd.Dose.Allocations)+Janssen.1st.Dose.Allocations
## Warning in Pfizer.2nd.Dose.Allocations + Pfizer.1st.Dose.Allocations +
## Moderna.1st.Dose.Allocations: longer object length is not a multiple of shorter
## object length
## Warning in Pfizer.2nd.Dose.Allocations + Pfizer.1st.Dose.Allocations +
## Moderna.1st.Dose.Allocations + : longer object length is not a multiple of
## shorter object length
## Warning in 0.5 * (Pfizer.2nd.Dose.Allocations + Pfizer.1st.Dose.Allocations + :
## longer object length is not a multiple of shorter object length
Cum.Allocation <-cumsum(All.Dose.Allocations)
#1.Data Exploration.
max_length <- max(c(length(Janssen.1st.Dose.Allocations),length(Moderna.1st.Dose.Allocations),length(Moderna.2nd.Dose.Allocations),length(Pfizer.1st.Dose.Allocations),length(Pfizer.2nd.Dose.Allocations)))
max_length
## [1] 1764
lengths_vector <- c(length(Janssen.1st.Dose.Allocations), length(Moderna.1st.Dose.Allocations), length(Moderna.2nd.Dose.Allocations), length(Pfizer.1st.Dose.Allocations), length(Pfizer.2nd.Dose.Allocations))
if (length(lengths_vector) > 0) {
max_length <- max(lengths_vector)
} else {
# Handle the case where all vectors have length zero
max_length <- 0
}
#creating a dummy vaccine_dataframe
df_vaccine <- data.frame(
Janssen.1st.Dose.Allocations = c(Janssen.1st.Dose.Allocations, rep(NA, max_length - length(Janssen.1st.Dose.Allocations))),
Moderna.1st.Dose.Allocations = c(Moderna.1st.Dose.Allocations, rep(NA, max_length - length(Moderna.1st.Dose.Allocations))),
Moderna.2nd.Dose.Allocations = c(Moderna.2nd.Dose.Allocations, rep(NA, max_length - length(Moderna.2nd.Dose.Allocations))),
Pfizer.1st.Dose.Allocations = c(Pfizer.1st.Dose.Allocations, rep(NA, max_length - length(Pfizer.1st.Dose.Allocations))),
Pfizer.2nd.Dose.Allocations = c(Pfizer.2nd.Dose.Allocations, rep(NA, max_length - length(Pfizer.2nd.Dose.Allocations))),
State = c(State, rep(NA, max_length - length(State))),
Date = c(Date, rep(NA, max_length - length(Date))),
All.Dose.Allocations = c(All.Dose.Allocations, rep(NA, max_length - length(All.Dose.Allocations))),
Cum.Allocation = c(Cum.Allocation, rep(NA, max_length - length(Cum.Allocation)))
)
str(df_vaccine)
## 'data.frame': 1764 obs. of 9 variables:
## $ Janssen.1st.Dose.Allocations: num 6400 2500 12300 2500 2000 1200 15600 19800 15100 6100 ...
## $ Moderna.1st.Dose.Allocations: num 41220 15800 79500 15800 12480 ...
## $ Moderna.2nd.Dose.Allocations: num 41220 15800 79500 15800 12480 ...
## $ Pfizer.1st.Dose.Allocations : num 54360 21420 104580 21420 17280 ...
## $ Pfizer.2nd.Dose.Allocations : num 54360 21420 104580 21420 17280 ...
## $ State : chr "Connecticut" "Maine" "Massachusetts" "New Hampshire" ...
## $ Date : POSIXct, format: "2021-06-21" "2021-06-21" ...
## $ All.Dose.Allocations : num 101980 39720 196380 39720 31760 ...
## $ Cum.Allocation : num 101980 141700 338080 377800 409560 ...
population_data <- IDDA::pop.state
population_data <- population_data%>% rename_at('State', ~'name')
df_vaccine <- df_vaccine%>%
mutate(name = sapply(State, gsub, pattern = " ",
replacement = ""))
#creating a left_join using Dplyr
df<- left_join(df_vaccine,population_data, by="name")
str(df)
## 'data.frame': 1764 obs. of 11 variables:
## $ Janssen.1st.Dose.Allocations: num 6400 2500 12300 2500 2000 1200 15600 19800 15100 6100 ...
## $ Moderna.1st.Dose.Allocations: num 41220 15800 79500 15800 12480 ...
## $ Moderna.2nd.Dose.Allocations: num 41220 15800 79500 15800 12480 ...
## $ Pfizer.1st.Dose.Allocations : num 54360 21420 104580 21420 17280 ...
## $ Pfizer.2nd.Dose.Allocations : num 54360 21420 104580 21420 17280 ...
## $ State : chr "Connecticut" "Maine" "Massachusetts" "New Hampshire" ...
## $ Date : POSIXct, format: "2021-06-21" "2021-06-21" ...
## $ All.Dose.Allocations : num 101980 39720 196380 39720 31760 ...
## $ Cum.Allocation : num 101980 141700 338080 377800 409560 ...
## $ name : Named chr "Connecticut" "Maine" "Massachusetts" "NewHampshire" ...
## ..- attr(*, "names")= chr [1:1764] "Connecticut" "Maine" "Massachusetts" "New Hampshire" ...
## $ population : int 3572665 1338404 6902149 1356458 1057315 626299 8908520 19542209 NA NA ...
#creating Doseperpop Variable using Mutate
library(dplyr)
df <- mutate(df, Doseperpop=Cum.Allocation/df$population)
#Making sure to drop all the NA values
df <- df[!(df$State=="American Samoa" | df$State=="Palau" | df$State == "Guam" | df$State == "Mariana Islands" | df$State == "Marshall Islands" | df$State == "NewYorkCity" | df$State == "PuertoRico" | df$State == "U.S.VirginIslands" | df$State == "Philadelphia"),]
#2.Visualization
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
plot1 <- plot_ly() %>%
# Add Cook County’s time series using mode: lines+markers
add_trace(data = df %>%
filter(State == 'Virginia'),x = ~Date , y = ~Janssen.1st.Dose.Allocations, type = 'scatter', mode = 'lines+markers',showlegend = TRUE, name = 'Janssen Dose') %>%
add_trace(data = df %>%
filter(State == 'Virginia'),x = ~Date , y = ~Pfizer.2nd.Dose.Allocations, type = 'scatter', mode = 'lines+markers',showlegend = TRUE, name = 'Pfizer 2nd dose')%>%
add_trace(data = df %>%
filter(State == 'Virginia'),x = ~Date , y = ~Pfizer.1st.Dose.Allocations, type = 'scatter', mode = 'lines+markers',showlegend = TRUE, name = 'Pfizer 1st dose')%>%
add_trace(data = df %>%
filter(State == 'Virginia'),x = ~Date , y = ~Moderna.2nd.Dose.Allocations, type = 'scatter', mode ='lines+markers',showlegend = TRUE, name = 'Moderna 2nd dose')%>%
add_trace(data = df %>%
filter(State == 'Virginia'),x = ~Date , y = ~Moderna.1st.Dose.Allocations, type = 'scatter', mode ='lines+markers',showlegend = TRUE, name = 'Moderna 1st dose')%>%
layout(
title = 'Vaccine Allocations from various providers',
xaxis = list(title = 'Date'),
yaxis = list(title = 'doses allocated')
)
library(htmlwidgets)
## Warning: package 'htmlwidgets' was built under R version 4.3.2
saveWidget(plot1, "Figure1.html", selfcontained = F)
plot1
plot2 <- plot_ly() %>%
add_trace(data = df %>%
filter(State == "Virginia"),
x = ~Date, y = ~Doseperpop, type = 'scatter', mode = 'lines+markers',
showlegend = TRUE, name = 'Virginia dosage allocation over-time' )
saveWidget(plot2, "Figure2.html", selfcontained = F)
plot2
#Figure 2
#3 District of columbia (D.C) cumulative vacccine allocations;
p5 <- plot_ly() %>%
add_trace(data = df %>%
filter(State == "District of Columbia"),x = ~Date, y =
~Cum.Allocation, type = 'scatter', mode = 'lines+markers',
showlegend = TRUE, name = 'D.C cumulative allocations'
)
p5
bar_data <- df[, c("State", "Janssen.1st.Dose.Allocations", "Moderna.1st.Dose.Allocations", "Moderna.2nd.Dose.Allocations", "Pfizer.1st.Dose.Allocations", "Pfizer.2nd.Dose.Allocations")]
state_bar_plot <-plot_ly(bar_data, x = ~State, y = ~Janssen.1st.Dose.Allocations, type = 'bar', name = 'Janssen 1st Dose') %>%
add_trace(y = ~Moderna.1st.Dose.Allocations, name = 'Moderna 1st Dose') %>%
add_trace(y = ~Moderna.2nd.Dose.Allocations, name = 'Moderna 2nd Dose') %>%
add_trace(y = ~Pfizer.1st.Dose.Allocations, name = 'Pfizer 1st Dose') %>%
add_trace(y = ~Pfizer.2nd.Dose.Allocations, name = 'Pfizer 2nd Dose') %>%
layout(title = 'Total Vaccine Allocations by State',
xaxis = list(title = 'State'),
yaxis = list(title = 'Total Allocations'),
barmode = 'stack')
state_bar_plot
## Warning: Ignoring 1140 observations
## Warning: Ignoring 57 observations
## Warning: Ignoring 57 observations
#allocation of vaccine vs population plot
avp_plot <- plot_ly(df, x = ~population, y = ~All.Dose.Allocations, text = ~State, mode = 'markers', type = 'scatter', marker = list(size = 10)) %>%
layout(title = 'Scatter Plot: Population vs. Vaccine Allocations',
xaxis = list(title = 'Population'),
yaxis = list(title = 'Vaccine Allocations'))
# Display the plot
avp_plot
## Warning: Ignoring 168 observations
pie_plot <- plot_ly(df, labels = ~State, values = ~Doseperpop, type = 'pie', hole = 0.4) %>%
layout(title = 'Proportion of Doses Allocated per Population',
showlegend = TRUE)
# Display the plot
pie_plot
library(plotly)
Cum_alloc_plot <- plot_ly(df, x = ~Date, y = ~Cum.Allocation, type = 'scatter', mode = 'lines', line = list(shape = "linear")) %>%
layout(title = 'Cumulative Vaccine Allocations Over Time',
xaxis = list(title = 'Date'),
yaxis = list(title = 'Cumulative Allocations'))
# Display the plot
Cum_alloc_plot
#map(d)
install.packages("sp")
## Installing package into 'C:/Users/Harinath/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## package 'sp' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'sp'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problem copying
## C:\Users\Harinath\AppData\Local\R\win-library\4.3\00LOCK\sp\libs\x64\sp.dll to
## C:\Users\Harinath\AppData\Local\R\win-library\4.3\sp\libs\x64\sp.dll:
## Permission denied
## Warning: restored 'sp'
##
## The downloaded binary packages are in
## C:\Users\Harinath\AppData\Local\Temp\RtmpYjUtEL\downloaded_packages
install.packages("sf")
## Installing package into 'C:/Users/Harinath/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## package 'sf' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'sf'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problem copying
## C:\Users\Harinath\AppData\Local\R\win-library\4.3\00LOCK\sf\libs\x64\sf.dll to
## C:\Users\Harinath\AppData\Local\R\win-library\4.3\sf\libs\x64\sf.dll:
## Permission denied
## Warning: restored 'sf'
##
## The downloaded binary packages are in
## C:\Users\Harinath\AppData\Local\Temp\RtmpYjUtEL\downloaded_packages
install.packages("leaflet")
## Installing package into 'C:/Users/Harinath/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## package 'leaflet' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\Harinath\AppData\Local\Temp\RtmpYjUtEL\downloaded_packages
install.packages("geojsonio")
## Installing package into 'C:/Users/Harinath/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## package 'geojsonio' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\Harinath\AppData\Local\Temp\RtmpYjUtEL\downloaded_packages
devtools::install_github("rstudio/leaflet")
## Downloading GitHub repo rstudio/leaflet@HEAD
## Warning in untar2(tarfile, files, list, exdir, restore_times): skipping pax
## global extended headers
## Warning in untar2(tarfile, files, list, exdir, restore_times): skipping pax
## global extended headers
## rlang (1.1.1 -> 1.1.3 ) [CRAN]
## glue (1.6.2 -> 1.7.0 ) [CRAN]
## cli (3.6.1 -> 3.6.2 ) [CRAN]
## utf8 (1.2.3 -> 1.2.4 ) [CRAN]
## fansi (1.0.4 -> 1.0.6 ) [CRAN]
## vctrs (0.6.3 -> 0.6.5 ) [CRAN]
## Rcpp (1.0.11 -> 1.0.12) [CRAN]
## digest (0.6.33 -> 0.6.34) [CRAN]
## stringi (1.7.12 -> 1.8.3 ) [CRAN]
## xfun (0.40 -> 0.42 ) [CRAN]
## jsonlite (1.8.7 -> 1.8.8 ) [CRAN]
## sp (2.1-2 -> 2.1-3 ) [CRAN]
## Installing 12 packages: rlang, glue, cli, utf8, fansi, vctrs, Rcpp, digest, stringi, xfun, jsonlite, sp
## Installing packages into 'C:/Users/Harinath/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
##
## There is a binary version available but the source version is later:
## binary source needs_compilation
## xfun 0.41 0.42 TRUE
##
## package 'rlang' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'rlang'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problem copying
## C:\Users\Harinath\AppData\Local\R\win-library\4.3\00LOCK\rlang\libs\x64\rlang.dll
## to C:\Users\Harinath\AppData\Local\R\win-library\4.3\rlang\libs\x64\rlang.dll:
## Permission denied
## Warning: restored 'rlang'
## package 'glue' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'glue'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problem copying
## C:\Users\Harinath\AppData\Local\R\win-library\4.3\00LOCK\glue\libs\x64\glue.dll
## to C:\Users\Harinath\AppData\Local\R\win-library\4.3\glue\libs\x64\glue.dll:
## Permission denied
## Warning: restored 'glue'
## package 'cli' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'cli'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problem copying
## C:\Users\Harinath\AppData\Local\R\win-library\4.3\00LOCK\cli\libs\x64\cli.dll
## to C:\Users\Harinath\AppData\Local\R\win-library\4.3\cli\libs\x64\cli.dll:
## Permission denied
## Warning: restored 'cli'
## package 'utf8' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'utf8'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problem copying
## C:\Users\Harinath\AppData\Local\R\win-library\4.3\00LOCK\utf8\libs\x64\utf8.dll
## to C:\Users\Harinath\AppData\Local\R\win-library\4.3\utf8\libs\x64\utf8.dll:
## Permission denied
## Warning: restored 'utf8'
## package 'fansi' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'fansi'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problem copying
## C:\Users\Harinath\AppData\Local\R\win-library\4.3\00LOCK\fansi\libs\x64\fansi.dll
## to C:\Users\Harinath\AppData\Local\R\win-library\4.3\fansi\libs\x64\fansi.dll:
## Permission denied
## Warning: restored 'fansi'
## package 'vctrs' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'vctrs'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problem copying
## C:\Users\Harinath\AppData\Local\R\win-library\4.3\00LOCK\vctrs\libs\x64\vctrs.dll
## to C:\Users\Harinath\AppData\Local\R\win-library\4.3\vctrs\libs\x64\vctrs.dll:
## Permission denied
## Warning: restored 'vctrs'
## package 'Rcpp' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'Rcpp'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problem copying
## C:\Users\Harinath\AppData\Local\R\win-library\4.3\00LOCK\Rcpp\libs\x64\Rcpp.dll
## to C:\Users\Harinath\AppData\Local\R\win-library\4.3\Rcpp\libs\x64\Rcpp.dll:
## Permission denied
## Warning: restored 'Rcpp'
## package 'digest' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'digest'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problem copying
## C:\Users\Harinath\AppData\Local\R\win-library\4.3\00LOCK\digest\libs\x64\digest.dll
## to
## C:\Users\Harinath\AppData\Local\R\win-library\4.3\digest\libs\x64\digest.dll:
## Permission denied
## Warning: restored 'digest'
## package 'stringi' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'stringi'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problem copying
## C:\Users\Harinath\AppData\Local\R\win-library\4.3\00LOCK\stringi\libs\x64\stringi.dll
## to
## C:\Users\Harinath\AppData\Local\R\win-library\4.3\stringi\libs\x64\stringi.dll:
## Permission denied
## Warning: restored 'stringi'
## package 'jsonlite' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'jsonlite'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problem copying
## C:\Users\Harinath\AppData\Local\R\win-library\4.3\00LOCK\jsonlite\libs\x64\jsonlite.dll
## to
## C:\Users\Harinath\AppData\Local\R\win-library\4.3\jsonlite\libs\x64\jsonlite.dll:
## Permission denied
## Warning: restored 'jsonlite'
## package 'sp' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'sp'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problem copying
## C:\Users\Harinath\AppData\Local\R\win-library\4.3\00LOCK\sp\libs\x64\sp.dll to
## C:\Users\Harinath\AppData\Local\R\win-library\4.3\sp\libs\x64\sp.dll:
## Permission denied
## Warning: restored 'sp'
##
## The downloaded binary packages are in
## C:\Users\Harinath\AppData\Local\Temp\RtmpYjUtEL\downloaded_packages
## installing the source package 'xfun'
## Warning in i.p(...): installation of package 'xfun' had non-zero exit status
## ── R CMD build ─────────────────────────────────────────────────────────────────
##
checking for file 'C:\Users\Harinath\AppData\Local\Temp\RtmpYjUtEL\remotes2a0010ee721\rstudio-leaflet-e15a997/DESCRIPTION' ...
✔ checking for file 'C:\Users\Harinath\AppData\Local\Temp\RtmpYjUtEL\remotes2a0010ee721\rstudio-leaflet-e15a997/DESCRIPTION'
##
─ preparing 'leaflet': (3s)
## checking DESCRIPTION meta-information ...
checking DESCRIPTION meta-information ...
✔ checking DESCRIPTION meta-information
##
─ checking for LF line-endings in source and make files and shell scripts (536ms)
##
─ checking for empty or unneeded directories
##
─ building 'leaflet_2.2.1.9000.tar.gz'
##
##
## Installing package into 'C:/Users/Harinath/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
library(geojsonio); library(leaflet); library(dplyr); library(sp); library(sf)
## Warning: package 'geojsonio' was built under R version 4.3.2
## Registered S3 method overwritten by 'geojsonsf':
## method from
## print.geojson geojson
##
## Attaching package: 'geojsonio'
## The following object is masked from 'package:base':
##
## pretty
## Warning: package 'sp' was built under R version 4.3.2
## Warning: package 'sf' was built under R version 4.3.2
## Linking to GEOS 3.11.2, GDAL 3.7.2, PROJ 9.3.0; sf_use_s2() is TRUE
library(geojsonio)
states <- geojsonio::geojson_read("https://rstudio.github.io/leaflet/json/us-states.geojson", what = "sp")
class(states)
## [1] "SpatialPolygonsDataFrame"
## attr(,"package")
## [1] "sp"
states <- sp::merge(states, df, by="name", duplicateGeoms = T)
m <- leaflet(states) %>%
setView(-96, 37.8, 4) %>%
addProviderTiles("MapBox", options = providerTileOptions(
id = "mapbox.light",
accessToken = Sys.getenv('MAPBOX_ACCESS_TOKEN')))
bins <- c(0, 25, 50, 75, 100, 125, 150)
pal <- colorBin("YlOrRd", domain = states$Doseperpop, bins = bins)
labels_cases <- sprintf("<strong>%s</strong><br/>Population: %g M<br>
Dosage per population: %g<br>
All dose allocation: %g",
states$name, round(states$population / (1e6), 2),
states$Doseperpop, states$All.Dose.Allocations) %>%
lapply(htmltools::HTML)
labels_cases[[1]]
Alabamam <- m %>% addPolygons(
fillColor = ~pal(states$Doseperpop),
weight = 2,
opacity = 1,
color = "white",
dashArray = "3",
fillOpacity = 0.7,
highlightOptions = highlightOptions(
weight = 5,
color = "#666",
dashArray = "",
fillOpacity = 0.7,
bringToFront = TRUE),
label = labels_cases,
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "15px",
direction = "auto"))
## Warning in pal(states$Doseperpop): Some values were outside the color scale and
## will be treated as NA
m <- m %>% addLegend(pal = pal, values = states$Doseperpop,
opacity = 0.7, title = "Dosage per population",
position = "bottomright")
m
#A high Dosageperpop value indicates that particular state performed poorly in allocating the vaccine doses for it’s communities.
Figure 4
install.packages("htmlwidgets")
## Warning: package 'htmlwidgets' is in use and will not be installed
library(htmltools)
## Warning: package 'htmltools' was built under R version 4.3.2
library(htmlwidgets)
saveWidget(m, file="Figure4.html", selfcontained = T)
SHINY APP
##******##
# Load necessary libraries
library(shiny)
## Warning: package 'shiny' was built under R version 4.3.2
library(shinydashboard)
## Warning: package 'shinydashboard' was built under R version 4.3.2
##
## Attaching package: 'shinydashboard'
## The following object is masked from 'package:graphics':
##
## box
library(plotly)
library(htmltools)
library(leaflet)
library(geojsonio)
library(sp)
library(sf)
# Assuming you have the necessary data preparation steps here...
# UI
ui <- fluidPage(
dashboardPage(
dashboardHeader(
title = "Covid-19 Vaccinations",
titleWidth = 230,
tags$li(class="dropdown", tags$a(href="https://harinathportfolio.online/",
icon("portfolio"), "My Portfolio", target="_blank")),
tags$li(class="dropdown", tags$a(href="https://www.linkedin.com/in/harinathmandha/",
icon("linkedin"), "Linkedin" , target="_blank")),
tags$li(class="dropdown", tags$a(href="https://github.com/hari255",
icon("github"), "Github", target="_blank"))
),
dashboardSidebar(
),
dashboardBody(
tabsetPanel(
tabPanel("Dataset",
icon = icon("database"),
tabsetPanel(
tabPanel("Dataset 1",
fluidRow(
column(width = 12, tags$h3("Dataset Details"),
tags$p("About: This dataset has been sourced from the Centers for Disease Control and Prevention (CDC), a reputable government agency dedicated to public health. The CDC is an authoritative source known for maintaining official health-related data in the United States. The dataset provides comprehensive insights into vaccine allocations across the USA and is inclusive of data from prominent vaccine providers such as Pfizer, Moderna, and Janssen. Specifically, it details the distribution of each vaccine dose, distinguishing between 1st and 2nd doses."),
tags$p("In addition to the CDC dataset, we have incorporated information from the IDDA R packages, which focuses on state-wise population data. This supplementary dataset enriches our analysis by providing demographic context for each state. Together, these datasets form a robust foundation for exploring and understanding the dynamics of vaccine allocations and population demographics in the United States."),
tags$p("Data Types: Numeric, Categorical, Datetime, object"),
tags$p("Structure: 1596 records * 12 columns"),
tags$h4("Description about columns"),
tags$p("Janssen.1st.Dose.Allocations: The number of Janssen (Johnson & Johnson) COVID-19 vaccine first doses allocated for
distribution in a specific location on a given date."),
tags$p("Moderna.1st.Dose.Allocations: The number of Moderna COVID-19 vaccine first doses allocated for distribution in a specific
location on a given date."),
tags$p("Moderna.2nd.Dose.Allocations: The number of Moderna COVID-19 vaccine second doses allocated for distribution in a specific
location on a given date."),
tags$p("Pfizer.1st.Dose.Allocations: The number of Pfizer COVID-19 vaccine first doses allocated for distribution in a specific
location on a given date."),
tags$p("Pfizer.2nd.Dose.Allocations: The number of Pfizer COVID-19 vaccine second doses allocated for distribution in a specific
location on a given date."),
tags$p("State: The name of the state for which vaccine allocation data is recorded."),
tags$p("Date: The date on which the vaccine allocation data was recorded, in POSIXct format."),
tags$p("All.Dose.Allocations: The total number of all COVID-19 vaccine doses (first and second doses combined) allocated for
distribution in a specific location on a given date."),
tags$p("Cum.Allocation: The cumulative total of COVID-19 vaccine doses allocated for distribution up to a specific date."),
tags$p("population: The population of the state for which demographic data is recorded."),
tags$p("Doseperpop: this column representS the ratio or percentage of vaccine doses per population, indicating the distribution level
relative to the total population."),
)
)
),
tabPanel("Dataset 2",
fluidRow(
column(width = 12, tags$h3("Dataset Details"),
tags$p("This dataset is obtained from the R package SP, containing essential geographical information such as longitude and latitude data for each state. The primary objective of incorporating this dataset is to leverage its geographical coordinates. Specifically, the longitude and latitude information is pivotal for creating an interactive map using the Leaflet package in R. To achieve this, the dataset has been merged with the main dataframe after transforming it into a spatialPolygon DataFrame. The seamless integration of geographical details enhances the visualization capabilities of the overall dataset, providing a spatial context to the analysis and facilitating the creation of dynamic and informative maps within the Shiny dashboard."),
tags$p("Structure: 52 rows x 5 columns"),
tags$p("Data Types: Float, Integer, Numeric"),
)
)
),
)
),
tabPanel("Interactive Viz",
icon = icon("chart-line"),
tabsetPanel(
tabPanel("Plot 1",
fluidRow(
column(width = 12, tags$h3("Virginia Vaccine allocations"), plotlyOutput("plot1",height = "600px")),
column(width = 12,
p("Plot Description: The interactive time-series plot depicts the
allocation trends of various COVID-19 vaccine doses in the state of
Virginia. The plot captures the distribution over time for different
vaccine providers, including Janssen (Johnson & Johnson), Pfizer,
and Moderna."),
tags$h4("Key Elements"),
p("Janssen Dose: The blue line with markers represents
the allocation trend of Janssen COVID-19 vaccine first doses in
Virginia. The plotted points connected by lines provide a clear
visualization of how the allocation of Janssen doses has evolved
over time."),
p("Pfizer 2nd Dose: The orange line with markers illustrates the
allocation trend of Pfizer COVID-19 vaccine second doses in
Virginia. This line graph shows the changes in allocation amounts
for the second dose of the Pfizer vaccine across different dates."),
p("Pfizer 1st Dose: The green line with markers showcases the
allocation trend of Pfizer COVID-19 vaccine first doses in Virginia.
Similar to the other lines, this graph represents the distribution
of first doses of the Pfizer vaccine
over time."),
p("Moderna 2nd Dose: The red line with markers displays the allocation
trend of Moderna COVID-19 vaccine second doses in Virginia. It
provides insights into how the allocation of the second dose from
Moderna has varied over the specified timeline."),
p("Moderna 1st Dose: The purple line with markers exhibits the
allocation trend of Moderna COVID-19 vaccine first doses in
Virginia. This line graph enables a visual understanding of the
distribution patterns for the first dose of the Moderna vaccine."),
p("Interactivity:The plot is interactive, allowing users to hover over
data points to view specific allocation values for each provider on
different dates. Additionally, the legend facilitates the selection
and deselection of specific providers for a more focused
analysis."),
)
)
),
tabPanel("Plot 2",
fluidRow(
column(width =12, tags$h4("This pie chart serves as a powerful visual tool for assessing the equitable distribution of COVID-19 vaccine doses
across states, offering a compelling snapshot of the impact of vaccination campaigns on different populations."),
plotlyOutput("pie_plot", height = "600px")), column(width = 12,
p("Plot Description:The pie chart provides a concise yet insightful representation of the distribution of COVID-19 vaccine doses
relative to the population across different states. This visually engaging plot allows for an immediate understanding of the
proportional impact of vaccination efforts in each state."),
tags$h4("Key Elements"),
p("Pie Slices: Each slice of the pie corresponds to a specific state, with the size of the slice directly proportional to
the proportion of vaccine doses allocated concerning the state's population."),
p("State Labels: The labels around the perimeter of the pie identify individual states, making it easy to associate each slice with
its respective location."),
p("Hole in the Center: The central hole in the pie, set at 40% (hole = 0.4), enhances the visual appeal of the chart and allows for
the inclusion of a title within the vacant center space."),
tags$h4("Insights"),
p("Proportional Distribution: The varying sizes of the pie slices reveal the relative distribution of vaccine doses across
states concerning their population sizes. Larger slices represent states with a higher proportion of vaccine doses relative to their
population."),
p("At-a-Glance Analysis: The pie chart offers a quick and intuitive overview, making it easy to identify states that have received a
substantial share of vaccine doses in comparison to their population."),
p("Legend: The legend, when displayed, provides additional information about the states corresponding to each slice, enhancing the
interpretability of the pie chart."))
)
),
tabPanel("Plot 3",
fluidRow(
column(width =12, tags$h4("This visually compelling plot serves as an effective tool for understanding the overall landscape of COVID-19
vaccine allocations across states and highlights the proportional contribution of each vaccine provider in the vaccination
efforts"),plotlyOutput("state_bar_plot", height = "600px")),
column(width = 12,
p("Plot Description: The stacked bar plot visualizes the comprehensive distribution of COVID-19 vaccine doses across different states.
The plot effectively represents the total allocations for each vaccine provider—Janssen (Johnson & Johnson), Moderna, and
Pfizer—through distinct bars stacked on top of one another for each state."),
tags$h4("Insights"),
p(" The stacked bars allow for a quick comparison of the total vaccine allocations between different states, revealing
patterns and disparities in distribution. The legend provides the option to selectively display or hide specific vaccine providers,
aiding in a focused analysis based on individual preferences."))
)
),
tabPanel("Plot 4",
fluidRow(
column(width =12, tags$h4("This scatter plot serves as a valuable tool for uncovering insights into the distribution dynamics of COVID-19
vaccine doses, facilitating a nuanced understanding of how states with varying populations are impacted by
vaccination efforts. "), plotlyOutput("avp_plot", height = "600px")),
column(width = 12,
p("This scatter plot visually explores the relationship between the population of states and their respective COVID-19 vaccine
allocations. This plot provides an interactive representation that allows for a nuanced understanding of how vaccine doses are
distributed in relation to the size of state populations."),
tags$h4("Insights"),
p("Population vs. Vaccine Allocations: The scatter plot enables the examination of how vaccine allocations scale concerning
the population of each state. States situated towards the upper-right portion of the plot may have both higher populations and larger
vaccine allocations."),
p("Identification of Outliers: Outliers, representing states with notable deviations in either population or vaccine allocations, can
be easily identified and analyzed for unique patterns or circumstances."),
p("Interactivity:The plot is interactive, allowing users to hover over data points to view specific details about each state."))
)
),
tabPanel("Plot 5",
fluidRow(
column(width =12, tags$h4("This line plot serves as a valuable tool for tracking the cumulative impact of COVID-19 vaccination efforts,
offering a clear depiction of how vaccine allocations have unfolded over time."), plotlyOutput("Cum_alloc_plot",
height = "600px")),
column(width = 12,
p("Plot Description: This line plot visually tracks the cumulative distribution of COVID-19 vaccine doses across a specified timeline.
This dynamic plot provides insights into how the cumulative allocations have evolved over the recorded dates, offering a
comprehensive view of the progression of vaccination efforts."),
tags$h4("Key Elements"),
p("Connected Line: The plot features a continuous line that connects data points, showcasing the cumulative vaccine allocations over
time. The linear shape of the line signifies the progression of cumulative allocations from one date to the next."),
tags$h4("Insights"),
p("Temporal Evolution: The plot allows for the observation of how cumulative vaccine allocations change over time. Upward trends in
the line reflect periods of increased allocations, while flat or downward trends may indicate stable or decreasing allocation
rates."),
p("Temporal Analysis:The plot is particularly useful for conducting a temporal analysis, revealing patterns and trends in the
cumulative distribution of vaccine doses over the specified timeline."))
)
),
)
),
tabPanel("Choropleth Map",
icon = icon("map"),
fluidRow(
column(
width =12,
h4("The map is interactive, enabling users to explore and analyze specific states. Hovering over states provides
detailed information, enhancing the interpretability of the choropleth map. This choropleth map serves as a valuable
tool for policymakers, public health officials, and researchers, offering a spatial perspective on the equitable
distribution of COVID-19 vaccine doses across the United States."),
leafletOutput("map", height="600px")
),
column(width = 12,
tags$h4("Choropleth Map Description:"),
p("The choropleth map dynamically visualizes the distribution of COVID-19 vaccine doses across different states
in the United States. Utilizing geographical data and statistical information, this interactive map offers
insights into the dosage per population for each state, providing a spatial context to vaccination
efforts."),
tags$h4("Key Elements:"),
p("Geographical Data: The map utilizes geographical data from the US States GeoJSON file, outlining the
boundaries of each state."),
p("Dosage per Population Color Gradient: The color gradient on the map represents the dosage per population for
each state. States with a higher dosage per population are shaded with warmer colors, while states with lower
ratios are depicted in cooler colors."),
p("Interactive Labels: Hovering over a state on the map reveals a tooltip with detailed information, including
the state's name, population, dosage per population, and total vaccine allocations."),
p("Legend: The legend positioned in the bottom-right corner of the map provides a reference for interpreting
the color scale. It indicates the dosage per population range associated with each color on the map."),
tags$h4("Insights"),
p("Dosage per Population Variation: The map highlights variations in dosage per population across states,
allowing for a quick assessment of how efficiently each state has allocated vaccine doses relative to its
population."),
p("Performance Evaluation: States with warmer colors may indicate more effective vaccine distribution, while
cooler colors suggest areas where the dosage per population might need improvement."),
tags$h4("Usage Note"),
p("A high dosage per population value for a state implies that the state may have faced challenges or performed
poorly in allocating vaccine doses to its communities.")
)
)
)
)
)
)
)
## The `name` provided ('portfolio') does not correspond to a known icon
server <- function(input, output) {
shinyjs::useShinyjs()
# Plot 1
output$plot1 <- renderPlotly({
plot_ly(data = df %>%
filter(State == 'Virginia')) %>%
add_trace(x = ~Date, y = ~Janssen.1st.Dose.Allocations, type = 'scatter', mode = 'lines+markers', showlegend = TRUE, name = 'Janssen Dose') %>%
add_trace(x = ~Date, y = ~Pfizer.2nd.Dose.Allocations, type = 'scatter', mode = 'lines+markers', showlegend = TRUE, name = 'Pfizer 2nd dose') %>%
add_trace(x = ~Date, y = ~Pfizer.1st.Dose.Allocations, type = 'scatter', mode = 'lines+markers', showlegend = TRUE, name = 'Pfizer 1st dose') %>%
add_trace(x = ~Date, y = ~Moderna.2nd.Dose.Allocations, type = 'scatter', mode = 'lines+markers', showlegend = TRUE, name = 'Moderna 2nd dose') %>%
add_trace(x = ~Date, y = ~Moderna.1st.Dose.Allocations, type = 'scatter', mode = 'lines+markers', showlegend = TRUE, name = 'Moderna 1st dose')
})
#plot 2
output$pie_plot <- renderPlotly({
plot_ly(df, labels = ~State, values = ~Doseperpop, type = 'pie', hole = 0.4) %>%
layout(showlegend = TRUE)
})
#plot 3
output$state_bar_plot <- renderPlotly({
plot_ly(bar_data, x = ~State, y = ~Janssen.1st.Dose.Allocations, type = 'bar', name = 'Janssen 1stDose') %>%
add_trace(y = ~Moderna.1st.Dose.Allocations, name = 'Moderna 1st Dose') %>%
add_trace(y = ~Moderna.2nd.Dose.Allocations, name = 'Moderna 2nd Dose') %>%
add_trace(y = ~Pfizer.1st.Dose.Allocations, name = 'Pfizer 1st Dose') %>%
add_trace(y = ~Pfizer.2nd.Dose.Allocations, name = 'Pfizer 2nd Dose') %>%
layout(title = 'Total Vaccine Allocations by State', xaxis = list(title = 'State'), yaxis = list(title = 'Total
Allocations'),barmode = 'stack')
})
output$avp_plot <-renderPlotly({
plot_ly(df, x = ~population, y = ~All.Dose.Allocations, text = ~State, mode = 'markers', type = 'scatter', marker = list(size = 10)) %>%
layout(title = 'Scatter Plot: Population vs. Vaccine Allocations',xaxis = list(title = 'Population'),yaxis = list(title = 'Vaccine Allocations'))
})
output$Cum_alloc_plot <- renderPlotly({
plot_ly(df, x = ~Date, y = ~Cum.Allocation, type = 'scatter', mode = 'lines', line = list(shape = "linear")) %>%
layout(title = 'Cumulative Vaccine Allocations Over Time', xaxis = list(title = 'Date'), yaxis = list(title = 'Cumulative Allocations'))
})
# Map
output$map <- renderLeaflet({
m
})
}
# Run the app
shinyApp(ui, server)